package com.chen.tliaswebtest.controller;

import com.chen.tliaswebtest.annotation.LogOperation;
import com.chen.tliaswebtest.pojo.PageResult;
import com.chen.tliaswebtest.pojo.Result;
import com.chen.tliaswebtest.pojo.Student;
import com.chen.tliaswebtest.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chen
 * @version 1.0
 * @create_date 2025/7/25
 * 学员管理控制层
 */
@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    private final StudentService studentService;

    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    // 学员列表数据的条件分页查询
    @GetMapping
    public Result list(String name, Integer degree, Integer clazzId,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult result = studentService.listByPage(name, degree, clazzId, page, pageSize);
        return Result.success(result);
    }

    // 批量删除员工的数据信息
    @DeleteMapping("/{ids}")
    @LogOperation
    public Result deleteStudent(@PathVariable List<Integer> ids) {
        studentService.removeByIds(ids);
        return Result.success();
    }

    // 添加学员信息
    @PostMapping
    @LogOperation
    public Result addStudent(@RequestBody Student student) {
        studentService.addStudent(student);
        return Result.success();
    }

    // 根据主键ID查询学员的信息
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable Integer id) {
        return Result.success(studentService.getStudentById(id));
    }

    // 修改学员的数据信息
    @PutMapping
    @LogOperation
    public Result updateStudent(@RequestBody Student student) {
        studentService.updateStudent(student);
        return Result.success();
    }

    // 修改学员的违纪数据信息

    /**
     * @param id    学员ID
     * @param score 扣除分数
     * @return 修改结果
     */
    @PutMapping("/violation/{id}/{score}")
    public Result updateStudentViolation(@PathVariable Integer id, @PathVariable Integer score) {
        studentService.updateStudentViolation(id, score);
        return Result.success();
    }
}
